using System;
using System.Drawing;

namespace HuaRongDaoGame.Models
{
    /// <summary>
    /// 华容道游戏中的方块类
    /// </summary>
    public class Block
    {
        /// <summary>
        /// 方块ID
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 方块名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 方块宽度（格子数）
        /// </summary>
        public int Width { get; set; }

        /// <summary>
        /// 方块高度（格子数）
        /// </summary>
        public int Height { get; set; }

        /// <summary>
        /// 方块左上角X坐标
        /// </summary>
        public int X { get; set; }

        /// <summary>
        /// 方块左上角Y坐标
        /// </summary>
        public int Y { get; set; }

        /// <summary>
        /// 方块颜色
        /// </summary>
        public Color Color { get; set; }

        /// <summary>
        /// 是否为曹操方块（最大的方块）
        /// </summary>
        public bool IsCaoCao { get; set; }

        /// <summary>
        /// 方块是否被选中
        /// </summary>
        public bool IsSelected { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public Block(int id, string name, int width, int height, int x, int y, Color color, bool isCaoCao = false)
        {
            Id = id;
            Name = name;
            Width = width;
            Height = height;
            X = x;
            Y = y;
            Color = color;
            IsCaoCao = isCaoCao;
            IsSelected = false;
        }

        /// <summary>
        /// 复制方块
        /// </summary>
        public Block Clone()
        {
            return new Block(Id, Name, Width, Height, X, Y, Color, IsCaoCao)
            {
                IsSelected = this.IsSelected
            };
        }

        /// <summary>
        /// 检查指定位置是否在方块内
        /// </summary>
        public bool Contains(int x, int y)
        {
            return x >= X && x < X + Width && y >= Y && y < Y + Height;
        }

        /// <summary>
        /// 检查方块是否可以移动到指定位置
        /// </summary>
        public bool CanMoveTo(int newX, int newY, int boardWidth, int boardHeight)
        {
            return newX >= 0 && newY >= 0 && 
                   newX + Width <= boardWidth && 
                   newY + Height <= boardHeight;
        }

        /// <summary>
        /// 移动方块到指定位置
        /// </summary>
        public void MoveTo(int newX, int newY)
        {
            X = newX;
            Y = newY;
        }

        /// <summary>
        /// 获取方块的边界矩形
        /// </summary>
        public Rectangle GetBounds()
        {
            return new Rectangle(X, Y, Width, Height);
        }

        /// <summary>
        /// 检查两个方块是否重叠
        /// </summary>
        public bool IntersectsWith(Block other)
        {
            return X < other.X + other.Width &&
                   X + Width > other.X &&
                   Y < other.Y + other.Height &&
                   Y + Height > other.Y;
        }
    }
} 